package com.yonyou.pmclouds.safeinspection.process;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.util.BeanHelper;
import com.yonyou.pmclouds.basecom.util.CommonFieldConst;
import com.yonyou.pmclouds.project.entity.ProjectConst;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import com.yonyou.pmclouds.project.rmiitf.ProjectSimpleQuery;
import com.yonyou.pmclouds.safeinspection.entity.SafeInspectionVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


@Component
public class ProjectstateBeforeProcess implements SingleProcessor<SafeInspectionVO> {


    @Resource
    private ProjectSimpleQuery simpleQuery;

    @Override
    public void process(SafeInspectionVO vo, SafeInspectionVO orig) throws BusinessException {
        if (vo!=null){
            String pk_project = BeanHelper.getProperty(vo, CommonFieldConst.PK_PROJECT) == null ?
                    (String) BeanHelper.getProperty(vo, CommonFieldConst.PKPROJECT)
                    : (String) BeanHelper.getProperty(vo, CommonFieldConst.PK_PROJECT);

            ProjectVO projectVO = simpleQuery.queryProject(pk_project);
            if (projectVO==null){
                throw new BusinessException("根据传过来的项目主键查不到该项目");
            }
            if (projectVO.getProjectState() == ProjectConst.STATE_END){
                throw new BusinessException("项目已结束,不能再发生业务");
            }

        }

    }
}
